// BurnCD.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "BurnCD.h"
#include "BurnCDDlg.h"
#include "globals.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CBurnCDApp

BEGIN_MESSAGE_MAP(CBurnCDApp, CWinApp)
	ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
END_MESSAGE_MAP()


// CBurnCDApp construction

CBurnCDApp::CBurnCDApp()
{
	// support Restart Manager
	m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_RESTART;
	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
}


// The one and only CBurnCDApp object

CBurnCDApp theApp;


// CBurnCDApp initialization

BOOL CBurnCDApp::InitInstance()
{
	// InitCommonControlsEx() is required on Windows XP if an application
	// manifest specifies use of ComCtl32.dll version 6 or later to enable
	// visual styles.  Otherwise, any window creation will fail.
	INITCOMMONCONTROLSEX InitCtrls;
	InitCtrls.dwSize = sizeof(InitCtrls);
	// Set this to include all the common control classes you want to use
	// in your application.
	InitCtrls.dwICC = ICC_WIN95_CLASSES;
	InitCommonControlsEx(&InitCtrls);
	
	CWinApp::InitInstance();
	AfxEnableControlContainer();

	// Create the shell manager, in case the dialog contains
	// any shell tree view or shell list view controls.
	CShellManager *pShellManager = new CShellManager;
	
	// Standard initialization
	// If you are not using these features and wish to reduce the size
	// of your final executable, you should remove from the following
	// the specific initialization routines you do not need
	// Change the registry key under which our settings are stored
	SetRegistryKey(REGISTRYKEY);
	
	//::CoInitializeEx(NULL, COINIT_MULTITHREADED);
	logger = NULL;
	out = NULL;
	char oldname[MAX_PATH],drive[_MAX_DRIVE], dir[_MAX_DIR], fname[_MAX_FNAME], ext[_MAX_EXT];
	logger = new CLogging;
	GetTempPath(MAX_PATH, oldname);
	_splitpath_s(oldname, drive, _MAX_DRIVE, dir, _MAX_DIR, fname, _MAX_FNAME, ext, _MAX_EXT );
	_makepath_s(oldname, MAX_PATH,  drive, dir, NULL, NULL);	
	out = logger->InitLogging(oldname, REGISTRYNAME);
	CBurnCDDlg dlg;
	m_pMainWnd = &dlg;
	if (__argc > 1)
	{
		dlg.m_argc = __argc;
		dlg.m_argv = __argv[1];
	}
	else
	{
		dlg.m_argc = 0;
		dlg.m_argv = "";
	}
	
	INT_PTR nResponse = dlg.DoModal();
	if (nResponse == IDOK)
	{
		// TODO: Place code here to handle when the dialog is
		//  dismissed with OK
	}
	else if (nResponse == IDCANCEL)
	{
		// TODO: Place code here to handle when the dialog is
		//  dismissed with Cancel
	}
	// Delete the shell manager created above.
	if (pShellManager != NULL)
	{
		delete pShellManager;
	}
	if (logger)
	{
		char str[200];
		memset(str, 0, 100);
		int Width = 7;
		int Div = 1024;
		char *divisor = "K";
		MEMORYSTATUSEX stat;
		stat.dwLength = sizeof (stat);
		GlobalMemoryStatusEx (&stat);
		SAFE_LOG(out, "Memory statistics", true);
		sprintf_s (str, 200, "%ld percent of memory is in use.", stat.dwMemoryLoad);
		SAFE_LOG(out, str, true);
		sprintf_s (str, 200,  "There are %*ld total %sB of physical memory.", Width, stat.ullTotalPhys/Div, divisor);
		SAFE_LOG(out, str, true);
		sprintf_s(str, 200, "There are %*ld free %sB of available physical memory.",  Width, stat.ullAvailPhys/Div, divisor);
		SAFE_LOG(out, str, true);
		sprintf_s (str, 200, "There are %*ld total %sB of paging file.",     Width, stat.ullTotalPageFile/Div, divisor);
		SAFE_LOG(out,  str, true);
		sprintf_s (str, 200, "There are %*ld free %sB of available paging file.",      Width, stat.ullAvailPageFile/Div, divisor);
		SAFE_LOG(out, str, true);
		sprintf_s (str, 200, "There are %*ld total %sB of virtual memory.",  Width, stat.ullTotalVirtual/Div, divisor);
		SAFE_LOG(out, str, true);
		sprintf_s (str, 200, "There are %*ld free %sB of available virtual memory.",   Width, stat.ullAvailVirtual/Div, divisor);
		SAFE_LOG(out, str, true);

	}
	//::CoUninitialize();
	// Since the dialog has been closed, return FALSE so that we exit the
	//  application, rather than start the application's message pump.
	return FALSE;
}

	